package edu.nf.exam.controller;


import com.github.pagehelper.PageInfo;
import edu.nf.exam.entity.ExamPaperResultInfo;
import edu.nf.exam.service.ExamPaperResultService;
import edu.nf.exam.service.impl.ExamPaperResultServiceImpl;
import org.nf.mvc.annotation.RequestMapping;
import org.nf.mvc.servlet.View;
import org.nf.mvc.view.JsonView;

import java.util.List;

/**
 * @Author : LLH
 * @create 2021/7/7
 */
public class ExamPaperResultController extends BaseController{

    /**
     * 添加
     * @param examPaperResultInfo
     * @return
     */
    @RequestMapping("/examPaperResult/add")
    public View add(ExamPaperResultInfo examPaperResultInfo){
        System.out.println(examPaperResultInfo);

        ExamPaperResultService service=new ExamPaperResultServiceImpl();
        try {
            service.add(examPaperResultInfo);
            return new JsonView(success(examPaperResultInfo.getExamPaperResultId()));
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonView(fail(500,e.getMessage()));
        }
    }

    /**
     * 查询
     * @param examPaperResultInfo
     * @return
     */
    @RequestMapping("/examPaperResult/select")
    public View select(ExamPaperResultInfo examPaperResultInfo){
        ExamPaperResultService service=new ExamPaperResultServiceImpl();
        try {
            List<ExamPaperResultInfo> list = service.select(examPaperResultInfo);

            JsonView jsonView = new JsonView(success(list));
            jsonView.setDateFormat("yyyy-MM-dd HH:mm:ss");
            return jsonView;
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonView(fail(500,e.getMessage()));
        }
    }

    /**
     * 分页查询
     * @param userName
     * @param examPaperName
     * @param levelName
     * @param subjectName
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/examPaperResult/selectByPage")
    public View selectByPage(String userName, String examPaperName,String levelName, String subjectName, Integer page, Integer limit){
        PageInfo<ExamPaperResultInfo> pageInfo = new ExamPaperResultServiceImpl().selectByPage(userName, examPaperName,levelName, subjectName, page, limit);

        JsonView jsonView = new JsonView(page(pageInfo));
        jsonView.setDateFormat("yyyy-MM-dd HH:mm:ss");
        return jsonView;
    }

    /**
     * 根据试卷ID查询成绩名次
     * @param examPaperId
     * @return
     */
    @RequestMapping("/examPaperResult/selectRankByExamPaperId")
    public View selectRankByExamPaperId(Integer examPaperId){
        List<ExamPaperResultInfo> list = new ExamPaperResultServiceImpl().selectRankByExamPaperId(examPaperId);
        return new JsonView(success(list));
    }
}
